日志样式

CDP协议详解

【概述】
CDP是Cisco Discovery Protocol的缩写, 它是由思科公司推出的一种私有的二层网络协议,它能够运行在大部分的思科设备上面。通过运行 CDP 协议,思科设备能够在与它们直连的设备之间分享有关操作系统软件版本,以及IP地址,硬件平台等相关信息。
【用途】
从CDP的字面意思我们可以理解到, 这是一种设备发现协议。 类似的协议有HP的LLDP(Link Layer Discovery Protocol)还有华为/H3C的 NDP(邻居发现协议)协议。 CDP是一个二层的网络协议, 默认每60 秒向01-00-0C-CC-CC-CC这个组播地址发送一次通告, 如果在180 秒内未获得先前邻居设备的CDP通告,它将清除原来收到的 CDP信息。因为它不依赖任何的三层协议,透过 CDP 协议,可以帮助我们解决一些三层错误配置的故障,比如错误的三层地址等等。
用途一:SNMP协议通过CDP MIB发现网络拓扑
SNMP 中结合使用 CDP 管理信息基础 MIB,能使网络管理应用获知被管理设备类型和相邻设备的 SNMP 代理地址,并向这些设备发送 SNMP 查询请求。Cisco 发现协议支持 CISCO-CDP-MIB。通过返回的响应信息,网络管理应用发现支持 CDP协议的网络设备,并依此生成发现的网络拓扑。
用途二:通过CDP协议发现相邻端口 Duplex不匹配
从CDP Version 2开始, CDP支持传送端口的Duplex, Native VLAN ID以及VTP Domain等新的 TLV 值。双工不匹配是一种比较难发现的网络错误,它并不会带来网络的中断但是它会造成某些应用性能的急剧下降。
如下例:
SW1--------SW2
在SW1上
SW1#sh int f0/1
FastEthernet0/1 is up, line protocol is up (connected)
Hardware is Fast Ethernet, address is 0013.1ac8.e581 (bia 0013.1ac8.e581)
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 100Mb/s, media type is 10/100BaseTX
input flow-control is off, output flow-control is unsupported
ARP type: ARPA, ARP Timeout 04:00:00
//忽略其他显示部分
SW1#sh run int f0/1
Building configuration...

Current configuration : 118 bytes
!
interface FastEthernet0/1
switchport trunk encapsulation dot1q
switchport mode trunk
speed 100
duplex full
end
同时交换机有错误消息提示
01:04:25: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on
FastEthernet0/1 (not half duplex), with SW2 FastEthernet0/1 (half duplex).
另外一台交换机上
SW2#sh int f0/1
FastEthernet0/1 is up, line protocol is up (connected)
Hardware is Fast Ethernet, address is 0012.01e8.6101 (bia 0012.01e8.6101)
MTU 1500 bytes, BW 100000 Kbit, DLY 100 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Half-duplex, 100Mb/s, media type is 10/100BaseTX//忽略其他部分
SW2#sh run int f0/1
Building configuration...

Current configuration : 94 bytes
!
interface FastEthernet0/1
switchport trunk encapsulation dot1q
switchport mode trunk
end
同时交换机上有如下错误提示
01:05:43: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on
FastEthernet0/1 (not full duplex), with SW1 FastEthernet0/1 (full duplex).
用途三:通过 CDP协议发现相邻Trunk端口的 Native VLAN ID 不一致
Trunk端口的Native VLAN ID 不一致会导致部分VLAN 通讯出现混乱。
交换机 SW1通过F0/1 与SW2的 F0/2连接。
如下例:
交换机SW1上
SW1#
01:07:51: %CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered
on FastEthernet0/1 (22), with SW2 FastEthernet0/1 (1).
SW1#sh run int f0/1
Building configuration...
Current configuration : 127 bytes
!
interface FastEthernet0/1
switchport trunk encapsulation dot1q
switchport trunk native vlan 22
switchport mode trunk
end
SW1#show cdp entry *
-------------------------
Device ID: SW2
Entry address(es):
Platform: Cisco WS-C3550-24, Capabilities: Switch IGMP
Interface: FastEthernet0/1, Port ID (outgoing port): FastEthernet0/1
Holdtime : 148 sec
Version :
Cisco IOS Software, C3550 Software (C3550-IPSERVICESK9-M), Version 12.2(35)SE,
RELEASE SOFTWARE (fc2)
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Sun 03-Dec-06 14:34 by yenanh

advertisement version: 2
Protocol Hello: OUI=0x00000C, Protocol ID=0x0112; payload len=27,
value=00000000FFFFFFFF010221FF000000000000001201E86100FF0000
VTP Management Domain: 'xixi'
Native VLAN: 1 (Mismatch) //对端 Native VLAN ID是 1
Duplex: full
Management address(es):
W1#sh int f0/1 trunk
Port Mode Encapsulation Status Native vlan
Fa0/1 on 802.1q trunking 22
Port Vlans allowed on trunk
Fa0/1 1-4094

Port Vlans allowed and active in management domain
Fa0/1 1,10,20-22,28,33-34,99-100,102,121,323

Port Vlans in spanning tree forwarding state and not pruned
Fa0/1 10,20-21,28,33-34,99-100,102,121,323
用途四:通过 CDP协议PoE 受电设备申请 PoE 电源分配
PoE 是Power Over Ethernet的缩写,也就是我们常说的 Inline Power,为解决一些小型以太网设备需要单独供电的而推出的一种集中化供电方式。 利用现有的5 类双绞线为那些小型的设备如IP Phone,无线的AP提供电力供应。
在PoE 供电系统中,我们把提供电力供应的设备叫 PSE(Power Supply Equipment)接收电力供应的叫PD(Powered Device) 。在思科设备中 PSE 往往是那些中心端点支持 PoE供电的交换机或者交换模块。而PD 设备则是那些需要远程供电的 IP Phone,无线 AP等等。
对于 PSE 和 PD 设备都为思科的设备,思科允许它们之间通过 CDP 交换信息,以期让PSE 设备获得PD 设备的真实需要的电源供应功率。
用途五:协同ODR工作
ODR是On-Demand Routing的缩写,直译可以翻译成“按需路由” ,我们可以把它看做是基于CDP协议的一种路由协议或者把它看做CDP协议的一种增强功能。在IOS 11.2及以后版本开始支持这个特性。 ODR适合用在那些Hub and Spoke型的网络结构中(Hub and Spoke的网络拓扑结果我们可以把它理解成一个中心点,多个分支的网络拓扑。集中分支) 。我们只需要在Hub中心路由器上启用router odr,分支路由器会自动在它的CDP更新中添加有关它网络的TLV信息。
在中心路由器R1 上
R1#config t
R1(config)#router odr //启动ODR路由。
R1(config-router)#end
R1#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route

Gateway of last resort is not set

10.0.0.0/24 is subnetted, 2 subnets
o 10.0.2.0 [160/1] via 192.168.0.2, 00:00:23 //学习到的 odr路由
C 10.0.1.0 is directly connected, Loopback0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/0
在分支路由器R2 上
R2#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route

Gateway of last resort is 192.168.1.1 to network 0.0.0.0

10.0.0.0/24 is subnetted, 1 subnets
C 10.0.2.0 is directly connected, Loopback0
192.168.0.0/30 is subnetted, 1 subnets
C 192.168.0.0 is directly connected, Serial0/0
o* 0.0.0.0/0 [160/1] via 192.168.1.1, 00:00:13 //学习到的缺省路由
【报文格式】
CDP协议是一个二层协议,它主要依赖某些二层协议作为它的承载层。
LLC/SNAP: OUI值0x00000C protocol ID 值 0x2000.
Cisco HDLC:Protocol ID 值为0x2000
PPP:Protocol ID 值为0x0207
CDP协议Decode例子如下:
Frame 1 (386 bytes on wire, 386 bytes captured)
Arrival Time: Oct 27, 2005 17:51:50.282947000
Time delta from previous packet: 0.000000000 seconds
Time since reference or first frame: 0.000000000 seconds
Frame Number: 1
Packet Length: 386 bytes
Capture Length: 386 bytes
Protocols in frame: eth:llc:cdp:data
IEEE 802.3 Ethernet
Destination: CDP/VTP (01:00:0c:cc:cc:cc) //特殊的组播目的地址
Source: Cisco_12:34:56 (00:07:85:12:34:56)
Length: 372
Logical-Link Control
DSAP: SNAP (0xaa) //DSAP和 SSAP 为 0xaa 说明后面跟着的是 SNAP
IG Bit: Individual
SSAP: SNAP (0xaa)
CR Bit: Command
Control field: U, func=UI (0x03)
000. 00.. = Command: Unnumbered Information (0x00)
.... ..11 = Frame type: Unnumbered frame (0x03)
Organization Code: Cisco (0x00000c) //SNAP OUI Field值
PID: CDP (0x2000) //Protocol ID
Cisco Discovery Protocol
Version: 2 //版
TTL: 180 seconds //TTL即为 Holdtime 计数器时间
Checksum: 0xc2c3
Device ID: LAN354802 //TLV值,设备 ID
Type: Device ID (0x0001)
Length: 13
Device ID: LAN354802
Addresses //TLV值,地址
Type: Addresses (0x0002)
Length: 17
Number of addresses: 1
IP address: 192.168.2.62
Protocol type: NLPID
Protocol length: 1
Protocol: IP
Address length: 4
IP address: 192.168.2.62
Port ID: FastEthernet0/7 //接口信息
Type: Port ID (0x0003)
Length: 19
Sent through Interface: FastEthernet0/7
Capabilities //支持的功能
Type: Capabilities (0x0004)
Length: 8
Capabilities: 0x0000000a
.... .... .... .... .... .... .... ...0 = Not a Router
.... .... .... .... .... .... .... ..1. = Is a Transparent Bridge
.... .... .... .... .... .... .... .0.. = Not a Source Route Bridge
.... .... .... .... .... .... .... 1... = Is a Switch
.... .... .... .... .... .... ...0 .... = Not a Host
.... .... .... .... .... .... ..0. .... = Not IGMP capable
.... .... .... .... .... .... .0.. .... = Not a Repeater
Software Version //软件版本信息
Type: Software version (0x0005)
Length: 225
Software Version: Cisco Internetwork Operating System Software
IOS (tm) C3500XL Software (C3500XL-C3H2S-M), Version
12.0(5)WC8, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2003 by cisco Systems, Inc.
Compiled Thu 19-Jun-03 12:37 by antonino
Platform: cisco WS-C3548-XL //平台信息
Type: Platform (0x0006)
Length: 21
Platform: cisco WS-C3548-XL
Protocol Hello: Cluster Management
Type: Protocol Hello (0x0008)
Length: 36
OUI: 0x00000C (Cisco)
Protocol ID: 0x0112 (Cluster Management)
Cluster Master IP: 0.0.0.0
UNKNOWN (IP?): 0xFFFFFFFF (255.255.255.255)
Version?: 0x01
Sub Version?: 0x01
Status?: 0x21
UNKNOWN: 0xFF
Cluster Commander MAC: 00:00:00:00:00:00
Switch's MAC: 00:07:85:12:34:56
UNKNOWN: 0xFF
Management VLAN: 100
VTP Management Domain: mynet //VTP管理域信息
Type: VTP Management Domain (0x0009)
Length: 10
VTP Management Domain: mynet
Native VLAN: 105 //NATIVE VLAN ID 信息
Type: Native VLAN (0x000a)
Length: 6
Native VLAN: 105
Duplex: Full
Type: Duplex (0x000b)
Length: 5
Duplex: Full
CDP协议报文格式

【配置管理】
CDP在思科设备上的配置管理非常简单。
(1) 全局下关闭打开CDP功能
缺省情况下CDP功能是打开的。
全局配置命令 cdp run //全局启用CDP
no cdp run //全局关闭CDP
配置范例:
R1#sh cdp //显示CDP全局配置信息
Global CDP information:
Sending CDP packets every 60 seconds //缺省每 60 秒发送一次 CDP通告
Sending a holdtime value of 180 seconds //CDP通告保持时间为 180秒
Sending CDPv2 advertisements is enabled //发送 CDP version 2的通告
R1#config t //进全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no cdp run //全局关闭CDP
R1(config)#exit
R1#
*Mar 1 00:07:45.351: %SYS-5-CONFIG_I: Configured from console by console
R1#sh cdp //这个时候我们再 show相关 CDP信息就会提示 CDP已经关闭
% CDP is not enabled

(2) 端口下关闭打开CDP功能
我们除了可以在全局状态下打开关闭 CDP 功能,我们也可以根据情况配置每个端口的
CDP功能的打开关闭
配置命令:
接口配置模式下 cdp enable //打开接口的 CDP功能
no cdp enable //关闭接口的 CDP功能
配置范例:
R1#sh cdp interface s0/0 //查看接口的 CDP配置
Serial0/0 is up, line protocol is up //接口状态
Encapsulation HDLC //接口封装格式
Sending CDP packets every 60 seconds //每 60 秒发送一次 CDP通告
Holdtime is 180 seconds //CDP通告保持时间为 180秒
R1#config t //进全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#int s0/0 //进接口配置模式
R1(config-if)#no cdp enable //关闭接口 CDP功能
R1(config-if)#exit
R1(config)#exit
R1#
*Mar 1 00:19:23.443: %SYS-5-CONFIG_I: Configured from console by console
R1#sh cdp interface s0/0 //这个时候我们显示CDP信息得到空白信息

R1#sh cdp //全局CDP功能还是打开的
Global CDP information:
Sending CDP packets every 60 seconds
Sending a holdtime value of 180 seconds
Sending CDPv2 advertisements is enabled

(3) 调整CDP计时器配置
缺省情况下发送计时器为60秒,保持计时器为 180秒
配置命令
全局配置模式下
cdp timer xx //配置发送计数器时间为 xx 秒
cdp holdtime xx //配置保持计时器时间为xx 秒
需要说明的有两点:
第一点:保持计时器时间必须大于发送计时器时间,建议为至少 2 倍发送计时器时
间。
第二点:保持计时器是本机发送出去的 CDP 通告所携带,通告接收设备,本 CDP
通告保持多长时间。而非针对本机收到的CDP通告。
配置范例:

R1#sh cdp //先查看一下当前 CDP计时器配置
Global CDP information:
Sending CDP packets every 80 seconds
Sending a holdtime value of 180 seconds
Sending CDPv2 advertisements is enabled
R1#config t //进全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#cdp timer ? //看看 cdp发送计时器的配置范围
<5-254> Rate at which CDP packets are sent (in sec)

R1(config)#cdp timer 90 //配置 CDP发送计时器为 90 秒
R1(config)#cdp holdtime ? //查看 CDP保持计时器的配置范围
<10-255> Length of time (in sec) that receiver must keep this packet

R1(config)#cdp holdtime 200 //配置 CDP保持计时器的时间为 200
R1(config)#exit
R1#
*Mar 1 00:37:43.059: %SYS-5-CONFIG_I: Configured from console by console
R1#sh cdp //通过show cdp,发现计时器配置已经更改
Global CDP information:
Sending CDP packets every 90 seconds
Sending a holdtime value of 200 seconds
Sending CDPv2 advertisements is enabled

(4) 允许发送CDP version2 的通告
缺省情况下思科设备是允许发送 CDP version2 的通告。
我们可以通过 no cdp advertise-v2关闭 CDP version2 通告的发送。
配置范例:
R1#sh cdp //检查 cdp全局配置
Global CDP information:
Sending CDP packets every 10 seconds
Sending a holdtime value of 30 seconds
Sending CDPv2 advertisements is enabled
R1#config t //进全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no cdp advertise-v2 //关闭发送 CDP version通告功能
R1(config)#exit
R1#show cdp //检查 CDP全局配置,已经关闭
Global CDP information:
Sending CDP packets every 10 seconds
Sending a holdtime value of 30 seconds
Sending CDPv2 advertisements is not enabled
R1#debug cdp packets //打开 CDP报文 debug模式
CDP packet info debugging is on
R1# //发送 version1的 CDP 报文
*Mar 1 00:52:23.759: CDP-PA: version 1 packet sent out on Serial0/0
对端R2 上
R2#show cdp nei detail //查看 CDP邻居详细信息
-------------------------
Device ID: R1
Entry address(es):
Platform: Cisco 3640, Capabilities: Router Switch IGMP
Interface: Serial0/0, Port ID (outgoing port): Serial0/0
Holdtime : 26 sec

Version :
Cisco IOS Software, 3600 Software (C3640-IS-M), Version 12.4(10a), RELEASE
SOFTW

ARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Wed 11-Oct-06 20:52 by prod_rel_team

advertisement version: 1

(5) CDP相关show命令
Show cdp //检查CDP全局配置信息
Show cdp neighbor
使用范例:
R1#show cdp //检查CDP全局配置信息
Global CDP information:
Sending CDP packets every 10 seconds //发送时间间隔
Sending a holdtime value of 30 seconds //保持时间间隔
Sending CDPv2 advertisements is not enabled //CDPv2的通告功能
R1#show cdp traffic //显示 CDP Counters,包含发送接收到的 CDP报文数量
CDP counters :
Total packets output: 96, Input: 137 //总共接收发送多少 CDP报文
Hdr syntax: 0, Chksum error: 0, Encaps failed: 1 //错误数量
No memory: 0, Invalid packet: 0, Fragmented: 0 //错误数量
CDP version 1 advertisements output: 62, Input: 54 //CDPv1的报文数量
CDP version 2 advertisements output: 34, Input: 83 //CDPv2的报文数量
R1#clear cdp counters //CDP Counters清零
R1#sh cdp traffic //检查 CDP Counters清零后的效果
No memory: 0, Invalid packet: 0, Fragmented: 0
CDP version 1 advertisements output: 0, Input: 1
CDP version 2 advertisements output: 0, Input: 1
R1#show cdp nei //显示设备发现的邻居情况
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater

Device ID Local Intrfce Holdtme Capability Platform Port ID
R2 Ser 0/0 21 R S I 3640 Ser 0/0
------------------------------------------------------------------------------------------------------
//Device ID 设备的主机名(Hostname)
//Local Intrfce :本地接口
//Holdtme:CDP通告信息保持多长时间,单位秒
//Capability: R代表是路由器,S支持交换功能,I支持 IGMP多播管理
//Platform:平台信息
//Port ID:
R1#clear cdp table //清除发现的邻居情况
R1#show cdp nei //检查清除后的效果,所有的邻居信息被清除
Capability Codes: R - Router, T - Trans Bridge, B - Source Route Bridge
S - Switch, H - Host, I - IGMP, r - Repeater

Device ID Local Intrfce Holdtme Capability Platform Port ID
R1#show cdp neighbors detail //显示 CDP邻居详细信息
-------------------------
Device ID: R2
Entry address(es):
Platform: Cisco 3640, Capabilities: Router Switch IGMP
Interface: Serial0/0, Port ID (outgoing port): Serial0/0
Holdtime : 19 sec
睿博工作室 .www.netlord.com.cn
第(12)页
Version :
Cisco IOS Software, 3600 Software (C3640-IS-M), Version 12.4(10a), RELEASE
SOFTW
ARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Wed 11-Oct-06 20:52 by prod_rel_team

advertisement version: 2

R1#show cdp interface //显示接口的 CDP配置信息
Serial0/0 is up, line protocol is up
Encapsulation HDLC
Sending CDP packets every 10 seconds
Holdtime is 30 seconds
Serial0/1 is up, line protocol is down
Encapsulation HDLC
Sending CDP packets every 10 seconds
Holdtime is 30 seconds
Serial0/2 is up, line protocol is down
Encapsulation HDLC
Sending CDP packets every 10 seconds
Holdtime is 30 seconds
Serial0/3 is up, line protocol is down
Encapsulation HDLC
Sending CDP packets every 10 seconds
Holdtime is 30 seconds
R1#sh cdp interface s0/0 //显示某个具体接口的 CDP配置信息
Serial0/0 is up, line protocol is up
Encapsulation HDLC
Sending CDP packets every 10 seconds
Holdtime is 30 seconds
R1#show cdp entry ?
* all CDP neighbor entries
WORD Name of CDP neighbor entry
R1#show cdp entry R2 //显示邻居 R2 的邻接信息,结果和 show cdp nei detail一致
-------------------------
Device ID: R2
Entry address(es):
Platform: Cisco 3640, Capabilities: Router Switch IGMP
Interface: Serial0/0, Port ID (outgoing port): Serial0/0
Holdtime : 17 sec

Version :
Cisco IOS Software, 3600 Software (C3640-IS-M), Version 12.4(10a), RELEASE
SOFTW
ARE (fc2)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2006 by Cisco Systems, Inc.
Compiled Wed 11-Oct-06 20:52 by prod_rel_team

advertisement version: 2

(6) CDP相关Debug命令
见下例:
R2#debug cdp ?
adjacency CDP neighbor info
events CDP events
ip CDP ip info
packets CDP packet-related information
R2#debug cdp packets //打开 debug CDP报文功能
CDP packet info debugging is on
R2#
*Mar 1 01:16:20.279: CDP-PA: version 2 packet sent out on Serial0/0
*Mar 1 01:16:20.283: CDP-PA: version 1 packet sent out on Serial0/0
*Mar 1 01:16:26.163: CDP-PA: Packet received from R1 on interface Serial0/0
*Mar 1 01:16:26.167: **Entry found in cache**

【补充说明】
(1) 常见的CDP错误日志信息

%CDP-4-DUPLEX_MISMATCH : duplex mismatch discovered on [chars] ([chars]), with
[chars] [chars] ([chars]).
解释:CDP发现双工配置不匹配。
建议:修改接口双工配置,保证它们工作在相同的双工状态下。

%CDP-4-NATIVE_VLAN_MISMATCH : Native VLAN mismatch discovered on [chars]
([dec]), with [chars] [chars] ([dec]).

解释: CDP发现某802.1Q Trunk端口 Native VLAN ID 不一致
建议: 将两端Native VLAN ID 配置修改为一致

(2) CDP Version1和Vesion 2 的区别
CDP Version1 和 Version2的主要区别在于 Version2 支持更多 TLV,比如交换机之间的 VVTP Domain,Duplex,Native VLAN ID 等等。这样极大的扩充了 CDP的功能。